// =============================================
// 功    能：控件初始化脚本,基于jquery
// 作    者：鼎永科技
// =============================================

//左补位 t:目标字符串;l:长度;s:补位字符
$.lpad = function (t, l, s) {
    var tp = "" + t;
    while (tp.length < l) {
        tp = s + tp;
    }
    return tp;
};
$.rpad = function (t, l, s) {
    var tp = "" + t;
    while (tp.length < l) {
        tp += s;
    }
    return tp;
};
//注释:清除头尾字符.示例:"中国" = "abc中国".trim("abc");
String.prototype.trimStart = function (trimStr) {
    if (!trimStr) {
        return this;
    }
    var temp = this;
    while (true) {
        if (temp.substr(0, trimStr.length) != trimStr) {
            break;
        }
        temp = temp.substr(trimStr.length);
    }
    return temp;
};
String.prototype.trimEnd = function (trimStr) {
    if (!trimStr) {
        return this;
    }
    var temp = this;
    while (true) {
        if (temp.substr(temp.length - trimStr.length, trimStr.length) != trimStr) {
            break;
        }
        temp = temp.substr(0, temp.length - trimStr.length);
    }
    return temp;
};
String.prototype.trim = function (trimStr) {
    var temp = trimStr;
    if (!trimStr) {
        temp = " ";
    }
    return this.trimStart(temp).trimEnd(temp);
};
//注释:类C#Format方法.示例:"test{0}test".format("xxx") = testxxxtest;
String.prototype.format = function () {
    var str = this;
    for (var i = 0; i < arguments.length; i++) {
        var re = new RegExp('\\{' + i + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

$.fn.extend({
    getFormJson: function () {
        var json = {};

        this.find("*").each(function (i, node) {
            var name, value;
            if ($(node).hasClass("droplist")) {
                return;
            }
            if ($(node).hasClass("datetimepicker")) {
                return;
            } else if ($(node).hasClass("textbox")) {
                var name = $(this).attr("conid");
                var input = $(node).find("input");
                if (input.length == 0) {
                    input = $(node).find("textarea");
                }
                if (input.length == 0) {
                    return;
                }
                value = input.val();
            }
            json[name] = value;
        });

        return json;
    },
    validateForm: function () {
        var hasError = false;
        this.find("*").each(function (i, node) {
            var name, value;
            if ($(node).hasClass("droplist")) {
                return;
            }
            if ($(node).hasClass("datetimepicker")) {
                return;
            } else if ($(node).hasClass("textbox")) {
                var input = $(node).find("input");
                if (input.length == 0) {
                    input = $(node).find("textarea");
                }
                if (input.length == 0) {
                    return;
                }
                if (!dys.get(input.attr("id")).validate()) {
                    hasError = true;
                }
            }
        });

        return !hasError;
    },
    dysInit: function () {
        this.find("*").each(function (i, node) {
            var id = $(node).attr("id");
            if (id != "txt222") {
                return;
            }
            if ($(node).hasClass("droplist")) {
                return;
            }
            if ($(node).hasClass("datetimepicker")) {
                return;
            } else if ($(node).hasClass("textbox")) {
                eval("var " + id + " = new dys.textBox('" + id + "');");
                return;
            }
        });
    }
});

var dys = {
    //日期选择器
    dateTimePicker: function (input, format, imageurl, func) {
        this.maintxt = input;
        if (typeof (input) == "string") {
            this.maintxt = $("#" + input);
        }
        this.maindiv = this.maintxt.parent();
        this.mainlink = this.maintxt.siblings("a");
        this.dateTime;
        this.value = this.maintxt.val();
        this.calendar = null;
        this.type = "dys.dateTimePicker";
        this.enable = true;
        var _this = this;
        var clickfunc = function (event) {
            event.stopPropagation();

            _this.calendar = new dys.calendar(_this.maintxt.val(), format, null, _this);
            _this.setLocation();
            $(top).scroll(function () {
                _this.setLocation();
            });
            _this.calendar.dateTimeChanged = function (date, strdate) {
                _this.dateTime = date;
                _this.value = _this.calendar.toformat(date);
                _this.maintxt.val(_this.calendar.toformat(date));
                if (func) func(date, strdate);
            };
            _this.maintxt.focus();
        };
        var link = this.maintxt.click(clickfunc).siblings("a").click(clickfunc);
        if (imageurl) {
            link.css({
                "background-image": "url(" + imageurl + ")"
            });
        }
    },
    //日期对象 div:日期展示标签;defaultdate:默认日期;type:1日期,2年月,3日期+时间,4
    calendar: function (defaultdate, format, div, picker, func) {
        var _this = this;

        this.maindiv = div; //展示日历的主div
        this.dateTime; //选中的日期
        this.format = format ? format : "yyyy-MM-dd"; //日期格式
        this.format_sta = "";
        this.value; //用字符串表示的值
        this.picker = picker; //日期选择器，如果是日期展示控件则为空
        this.maintxt; //用于回发的HiddenField对象
        this.dateTimeChanged = func;
        this.type = "dys.calendar";

        if (typeof (div) == "string") {
            this.maindiv = $("#" + div);
        }
        this.format_sta = this.format.replace("年", "-").replace("月", "-").replace("日", "").replace("时", ":").replace("分", ":").replace("秒", "").replace(new RegExp('/', 'g'), '-').trim("-").trim(":");
        if (defaultdate) {
            //格式化默认日期，并赋值给dateTime
            var defdate = defaultdate.replace("年", "-").replace("月", "-").replace("日", "").replace("时", ":").replace("分", ":").replace("秒", "").replace(new RegExp('/', 'g'), '-').trim("-").trim(":");
            var dates = defdate.split(" ");
            this.dateTime = new Date();
            for (var i = 0; i < dates.length; i++) {
                if (dates[i].indexOf("-") >= 0) {
                    var ts = dates[i].split("-");
                    this.dateTime.setFullYear(Number(ts[0]));
                    if (ts[1] != null) {
                        this.dateTime.setMonth(Number(ts[1] - 1));
                        if (ts[2] != null) {
                            this.dateTime.setDate(Number(ts[2]));
                        }
                    }
                } else if (dates[i].indexOf(":") >= 0) {
                    var ts = dates[i].split(":");
                    this.dateTime.setHours(Number(ts[0]));
                    if (ts[1] != null) {
                        this.dateTime.setMinutes(Number(ts[1]));
                        if (ts[2] != null) {
                            this.dateTime.setSeconds(Number(ts[2]));
                        }
                    }
                }
            }
        } else {
            this.dateTime = new Date();
        }

        if (!div) {
            //当是日期选择器时，生成主框架，如果是日期控件，则不生成
            var divs = top.$(".dy_calendar.picker");
            if (divs.length <= 0) {
                var html = "<div class=\"dy_calendar picker\"><div class=\"calhead\"><a href=\"javascript:;\" class=\"lefty\"></a><a href=\"javascript:;\" class=\"leftm\"></a><span><a href=\"javascript:;\" style=\"width:48px;\">" + this.dateTime.getFullYear() + "年</a><a href=\"javascript:;\" style=\"width:36px;\">" + $.lpad(this.dateTime.getMonth() + 1, 2, '0') + "月</a></span><a href=\"javascript:;\" class=\"righty\"></a><a href=\"javascript:;\" class=\"rightm\"></a></div>"
                    + "<ul><li class=\"s\">日</li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul>"
                    + "<div class=\"caldate\"><div>";
                html += "</div></div>";
                html += "<div class=\"caltime\">";
                html += "<div><input type=\"text\" value=\"" + $.lpad(this.dateTime.getHours(), 2, "0") + "\" /><b>时</b></div>";
                html += "<div><input type=\"text\" value=\"" + $.lpad(this.dateTime.getMinutes(), 2, "0") + "\" /><b>分</b></div>";
                html += "<div><input type=\"text\" value=\"" + $.lpad(this.dateTime.getSeconds(), 2, "0") + "\" /><b>秒</b></div>";
                html += "<div class=\"updown\"><a href=\"javascript:;\" class=\"up\"></a><a href=\"javascript:;\" class=\"down\"></a></div></div>"
                html += "<div class=\"btns\"><div><a href=\"javascript:;\">今日</a><a href=\"javascript:;\">清空</a><a href=\"javascript:;\">关闭</a></div></div></div>";
                this.maindiv = $(html).css({ display: "none", zIndex: dys.zIndex }).appendTo($(top.document.body)).mousedown(function (event) {
                    event.stopPropagation();
                });
            } else {
                this.maindiv = divs;
            }
            if (this.format_sta != "yyyy-MM") {
                this.create("");
            }
            this.maintxt = picker.maintxt;
        } else {
            this.initcdate();
            this.maintxt = this.maindiv.children("input");
        }
        if (picker) {
            this.maindiv.attr("maintxt", picker.maintxt.attr("id"));
        }

        //判断各种格式下显示的状态var height = 256;
        var d1, d2, d3, d4, d5, d6, d7, height = 256;
        if (this.format_sta == "yyyy-MM-dd") {
            d1 = "1px";
            d2 = "";
            d3 = "";
            d4 = "";
            d5 = "none";
            d6 = "0px";
            d7 = "今日";
            height = 216;
        } else if (this.format_sta == "yyyy-MM") {
            d1 = "1px";
            d2 = "";
            d3 = "";
            d4 = "";
            d5 = "none";
            d6 = "0px";
            d7 = "本月";
            height = 216;
        } else if (this.format_sta == "yyyy-MM-dd HH:mm:ss") {
            d1 = "0px";
            d2 = "";
            d3 = "";
            d4 = "";
            d5 = "";
            d6 = "0px";
            d7 = "今日";
            height = 256;
        } else if (this.format_sta == "HH:mm:ss") {
            d1 = "0px";
            d2 = "none";
            d3 = "none";
            d4 = "none";
            d5 = "";
            d6 = "1px solid #dedede";
            d7 = "当时";
            height = 73;
        }
        this.maindiv.children(".btns").css({ borderTopWidth: d1 });
        this.maindiv.children(".calhead").css({ display: d2 });
        this.maindiv.children("ul").css({ display: d3 });
        this.maindiv.children(".caldate").css({ display: d4 });
        this.maindiv.children(".caltime").css({ display: d5, borderTop: d6 });
        this.maindiv.attr("height", height);

        this.maindiv.find("a").focus(function () {
            this.blur();
        });
        //生成选择年或月的html
        var createym = function (type, date) {
            var html = "";
            for (var i = 0; i < 12; i++) {
                var cls = "";
                if ((type == "year" && date.getFullYear() == date.getFullYear() - 7 + i) || (type == "month" && date.getMonth() == i)) {
                    cls = " class=\"d\"";
                }
                html += "<a href=\"javascript:;\" onfocus=\"this.blur();\"" + cls + ">" + (type == "year" ? (date.getFullYear() - 7 + i) + "年" : $.lpad(i + 1, 2, "0") + "月") + "</a>";
            }
            return html;
        };
        //选择年月面板中a标签事件
        var calymclick = function (event) {
            event.stopPropagation();
            var type = $(this).html().indexOf("年") >= 0 ? "year" : "month";
            var valx = Number($(this).html().replace("年", "").replace("月", ""));
            if (type == "year") {
                _this.dateTime.setFullYear(valx);
            }
            else {
                _this.dateTime.setMonth(valx - 1);
            }

            var as = _this.maindiv.find(".calhead span a");
            if (_this.format_sta == "yyyy-MM") {
                if (type == "year") {
                    as.eq(1).click();
                    as.eq(0).html(_this.dateTime.getFullYear() + "年");
                } else {
                    _this.maindiv.remove();
                }
                _this.changed();
            } else {
                var calym = _this.maindiv.children(".calym");
                calym.animate({
                    height: 0
                }, 200, function () {
                    calym.remove();
                    var val = Number(as.eq(0).html().replace("年", "").replace("月", ""));
                    _this.create(val > valx ? "left" : "right");
                });
                as.parent().parent().children("a").removeAttr("style");
            }
        }
        //上一年，上一月，下一月，下一年按钮
        var lrclick = function () {
            var calym = _this.maindiv.children(".calym");
            if (calym.length > 0) { //当选择年月时点上一年/下一年按钮
                var isleft = $(this).attr("class").indexOf("left") >= 0;
                _this.dateTime.setFullYear(_this.dateTime.getFullYear() + (isleft ? -12 : 12));
                _this.maindiv.find(".calhead span a").eq(0).html(_this.dateTime.getFullYear() + "年");

                $("<div class=\"calym\">" + createym("year", _this.dateTime) + "</div>").css({
                    position: "absolute",
                    top: 26,
                    left: isleft ? 0 - calym.width() - 16 : calym.width() + 16
                }).appendTo(_this.maindiv).animate({
                    left: 0
                }, 200).children("a").click(calymclick);

                calym.animate({
                    left: isleft ? calym.width() + 16 : 0 - calym.width() - 16
                }, 200, function () {
                    calym.remove();
                });
            } else {
                _this.create($(this).attr("class"));
            }
        };
        this.maindiv.find(".calhead .lefty").unbind("click").click(lrclick).siblings(".leftm").unbind("click").click(lrclick).siblings(".righty").unbind("click").click(lrclick).siblings(".rightm").unbind("click").click(lrclick);
        //选择年月按钮
        this.maindiv.find(".calhead span a").unbind("click").click(function () {
            var calym = _this.maindiv.children(".calym");
            if (calym.length <= 0) {
                calym = $("<div class=\"calym\"></div>").appendTo(_this.maindiv).css({
                    position: "absolute",
                    top: 26,
                    height: 0
                });
            }

            var type = $(this).html().indexOf("年") >= 0 ? "year" : "month";
            if (type == "month") {
                $(this).parent().parent().children("a").css({ visibility: "hidden" });
            }
            else {
                $(this).parent().parent().children("a").removeAttr("style").each(function () {
                    if ($(this).attr("class").indexOf("m") >= 0) {
                        $(this).css({ visibility: "hidden" });
                    }
                });
            }
            var val = Number($(this).html().replace("年", "").replace("月", ""));
            var html = createym(type, _this.dateTime);
            calym.html(html);
            calym.css({ height: 0, display: "" }).animate({ height: 132 }, 200);
            calym.children("a").click(calymclick);
        });
        if (this.format_sta == "yyyy-MM") {
            this.maindiv.find(".calhead span a").eq(0).click();
        } else {
            this.maindiv.find(".calym").css({ display: "none" });
        }
        var caltime = this.maindiv.children(".caltime");
        var currinput = null;
        //获取时分秒最大值
        var getmax = function (input) {
            var max = 24;
            var type = input.siblings("b").html();
            if (type == "时") {
                max = 24;
            } else {
                max = 60;
            }
            return max;
        }
        //设置时分秒
        var setinput = function (input, zhi, type) {
            var max = getmax(input);
            var val = zhi;
            if (val >= max) {
                val = 0;
            } else if (val < 0) {
                val = max - 1;
            }
            input.val($.lpad(val, 2, '0'));
            if (type != "blur") {
                input.select();
            }
            var type = input.siblings("b").html();
            if (type == "时") {
                _this.dateTime.setHours(val);
            }
            else if (type == "分") {
                _this.dateTime.setMinutes(val);
            }
            else if (type == "秒") {
                _this.dateTime.setSeconds(val);
            }
            _this.changed();
        }
        //时分秒设置
        caltime.find("input").unbind("click").click(function (event) {
            event.stopPropagation();
            $(this).select();
            currinput = $(this);
        }).unbind("mousewheel").mousewheel(function (event, delta, deltaX, deltaY) { //滚轮事件
            event.stopPropagation();
            setinput($(event.target), Number($(this).val()) + delta);
            currinput = $(event.target);
            return false;
        }).unbind("keydown").keydown(function (event) { //只能输入数字
            if (!((event.which >= 48 && event.which <= 57) || (event.which >= 96 && event.which <= 105))) {
                return false;
            }
        }).unbind("keyup").keyup(function (event) { //超过最大值取最大值-1
            var val = Number($(this).val());
            var max = getmax($(this));
            if (val >= max) {
                $(this).val(max - 1);
            }
            else if (val < 0) {
                $(this).val(0);
            }
        }).unbind("blur").blur(function (event) { //失去焦点时检测值
            setinput($(this), Number($(this).val()), "blur");
            $(this).val($.lpad($(this).val(), 2, "0"));
        });
        //上下箭头按钮
        caltime.find("a").unbind("click").click(function (event) {
            event.stopPropagation();
            if (currinput == null) {
                currinput = caltime.find("input").eq(0);
            }
            setinput(currinput, Number(currinput.val()) + ($(this).attr("class") == "up" ? 1 : -1));
        });
        //今日、清空、关闭
        var btns = this.maindiv.find(".btns a");
        btns.eq(0).html(d7);
        btns.unbind("click").click(function () {
            var btn = $(this).html();
            if (btn == "今日") {
                var date = new Date();
                var type = _this.dateTime > date ? "left" : "right";
                if (_this.dateTime.getFullYear() == date.getFullYear() && _this.dateTime.getMonth() == date.getMonth()) {
                    type = "";
                }
                _this.dateTime.setFullYear(date.getFullYear());
                _this.dateTime.setMonth(date.getMonth());
                _this.dateTime.setDate(date.getDate());
                _this.create(type);
                if (_this.picker) {
                    if (!_this.format_sta.indexOf("HH") < 0) {
                        $(".dy_calendar.picker").remove();
                    }
                }
            } else if (btn == "本月") {
                var date = new Date();
                _this.dateTime.setFullYear(date.getFullYear());
                _this.dateTime.setMonth(date.getMonth());
                _this.changed();
                $(".dy_calendar.picker").remove();
            } else if (btn == "当时") {
                _this.dateTime = new Date();
                _this.changed();
                $(".dy_calendar.picker").remove();
            } else if (btn == "清空") {
                picker.maintxt.val("");
                $(".dy_calendar.picker").remove();
            } else {
                $(".dy_calendar.picker").remove();
            }
        });
    },
    dropListItem: function (text, value, selected, second) {
        this.text = text;
        this.value = value;
        this.selected = selected;
        this.second = second; //辅助文本数组
    },
    //下拉菜单控件
    dropList: function (conid, itemcount, multiple, selectedValue, changefunc, enable) {
        var _this = this;
        this.control = $("#" + conid);
        if (this.control.length == 0) {
            this.control = $("<div id=\"" + conid + "\" class=\"droplist textbox\"><div class=\"main\">"
                + "<input type=\"text\" name=\"" + conid + "$" + conid + "_text\" id=\"" + conid + "_" + conid + "_text\" autocomplete=\"off\" />"
                + "<input type=\"hidden\" name=\"" + conid + "$" + conid + "_value\" id=\"" + conid + "_" + conid + "_value\" />"
                + "</div><a href=\"javascript:;\"></a><div class=\"droplistdiv\" style='display:none;'><div class=\"dropmain\">"
                + "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"></table></div>"
                + "<a href=\"javascript:;\" class=\"link\"></a><div class=\"splitwhite\">&nbsp;</div></div></div>");
        }
        this.id = conid;
        this.maindiv = this.control;
        this.multiple = multiple;
        this.type = "dys.dropList";
        this.valuehidden = this.maindiv.find("input[type=hidden]"); //选中的值
        this.droplistdiv = this.maindiv.find(".droplistdiv").css({ zIndex: dys.zIndex }).appendTo(top.document.body); //下拉主div
        this.maintable = this.droplistdiv.find("table");
        this.itemcount = itemcount;
        this.keywords = "";
        this.items = [];
        this.multiple = multiple;
        this.seCount = -1;
        this.selectedValue = "";
        this.selectedText = "";
        this.selectedRow;
        this.selectedRows;
        this.enable = enable == null ? true : enable;
        if (changefunc) {
            this.changed = changefunc;
        }
        this.maintxt = this.maindiv.children(".main").children(":text");
        this.mainlink = this.maintxt.parent().siblings("a").click(function (event) {
            _this.maintxt.focus().click();
        });
        this.selectedValue = selectedValue;
        //this.niceScroll = this.droplistdiv.children(".dropmain").niceScroll(); //滚动条
        if (!multiple) {
            _this.maintable.find("tr[value='" + this.valuehidden.val() + "']").addClass("selected");
            this.selectedRows = _this.maintable.find("tr.selected");
        } else {
            var sx = "";
            var sxs = this.valuehidden.val().split(",");
            for (var i = 0; i < sxs.length; i++) {
                sx += (sx == "" ? "" : ",") + "tr[value='" + sxs[i] + "']";
            }
            _this.maintable.find(sx).addClass("selected");
        }
        this.itemClick = function (event) {
            //过滤i标签
            var temp = $("<div>" + $(this).children("td.m").html() + "</div>");
            temp.find("i").each(function () {
                var xx = $(this).html();
                $(this).replaceWith(xx);
            });
            var text = temp.text();

            if (!multiple) {
                _this.maintxt.val(text);
                _this.valuehidden.val($(this).attr("value"));
                _this.selectedValue = $(this).attr("value");
                $(this).addClass("selected");
                if (_this.selectedRow != null) {
                    _this.selectedRow.removeClass("selected");
                }
                _this.maintxt.removeAttr("in");
                _this.maintxt.blur();
                _this.droplistdiv.hide();
                _this.maintxt.val(text);
                _this.selectedText = text;
            } else {
                var checkbox = $(this).find(".c span");
                var seltext = "";
                if (checkbox.hasClass("checked")) {
                    checkbox.removeClass("checked");
                    $(this).removeClass("selected");
                    seltext = ("," + _this.selectedText + ",").replace("," + text + ",", ",").trim(",");
                    var value = ("," + _this.valuehidden.val() + ",").replace("," + $(this).attr("value") + ",", "").trim(",");
                    _this.valuehidden.val(value);
                    _this.selectedValue = value;
                } else {
                    checkbox.addClass("checked");
                    $(this).addClass("selected");
                    seltext = _this.selectedText + (_this.selectedText == "" ? "" : ",") + text;
                    var value = _this.valuehidden.val() + (_this.valuehidden.val() == "" ? "" : ",") + $(this).attr("value");
                    _this.valuehidden.val(value);
                    _this.selectedValue = value;
                }
                ;
                _this.selectedText = seltext;
                _this.selectedRows = _this.maintable.find("tr.selected");
                if (_this.droplistdiv[0].style.display != "none") {
                    _this.maintxt.focus();
                }
            }
            _this.selectedRow = $(this);
            if (_this.changed) {
                _this.changed(_this.selectedValue);
            }
            event.stopPropagation();
        };
        var trs = _this.maintable.find("tr").mouseover(function () {
            $(this).addClass("hover");
        }).mouseout(function () {
            $(this).removeClass("hover");
        }).click(this.itemClick);
        if (trs.length > 0) {
            this.seCount = $(trs[0]).children("td").length - 1;
            if (this.multiple) {
                this.seCount--;
            }
        }
        this.droplistdiv.mouseover(function () {
            _this.maintxt.attr("in", "1");
        }).mouseout(function () {
            _this.maintxt.removeAttr("in");
        });

        this.ref();
        setTimeout(function () {
            _this.initstyle()
        }, 100);
        $(window).resize(function () {
            _this.initstyle();
            if (_this.droplistdiv[0].style.display == "") {
                _this.show();
            }
        });
        dys.append(this);
    },
    //复选框控件
    checkBox: function (conid, name, text, checked, func) {
        this.control = $("#" + conid);
        this.id = conid;
        this.type = "dys.checkBox";
        this.enable = true;
        var name = name != null ? name : conid;
        if (this.control.length == 0) {
            if (text == null) {
                alert("创建控件失败");
                return;
            }
            if (checked == null) {
                checked = false;
            }
            this.control = $("<span class=\"checkbox\" ><input id=\"" + conid + "\" type=\"checkbox\""
                + (checked == true ? " checked=\"" + checked + "\"" : "") + " name=\"" + name + "\" /><label for=\"" + conid + "\">" + text + "</label></span>");
        } else {
            this.control = this.control.parent();
        }
        var input = this.control.children("input");
        this.checked = input.prop("checked");
        this.text = this.control.children("label").html();
        if (func != null) {
            this.changed = func;
        }
        this.ref();
        dys.append(this);
    },
    //单选框控件
    radioButton: function (conid, name, text, checked, func) {
        this.control = $("#" + conid);
        this.id = conid;
        this.type = "dys.radioButton";
        this.enable = true;
        var name = name != null ? name : conid;
        if (this.control.length == 0) {
            if (text == null) {
                alert("创建控件失败");
                return;
            }
            if (checked == null) {
                checked = false;
            }
            this.control = $("<span class=\"radiobutton\" ><input id=\"" + conid + "\" type=\"radio\""
                + (checked == true ? " checked=\"" + checked + "\"" : "") + " name=\"" + name + "\" /><label for=\"" + conid + "\">" + text + "</label></span>");
        } else {
            this.control = this.control.parent();
        }
        var input = this.control.children("input");
        this.checked = input.prop("checked");
        this.text = this.control.children("label").html();
        if (func != null) {
            this.changed = func;
        }
        this.ref();
        dys.append(this);
    },
    //弹出框 框体
    dialogBox: function (coru, pars, mode) {
        this.id = "";
        this.moveMode = "";
        this.topHeight;
        this.bottomHeight;
        this.leftWidth;
        this.rightWidth;
        this.minWidth = 100;
        this.minHeight = 60;
        this.full;
        this.fulliframe;
        this.obj;
        this.data;
        this.pars = pars;
        this.zIndex = -1;
        this.type = "dys.dialogBox";
        var btnFocus = null;
        if (pars == null) {
            pars = {};
        }
        if (pars.zIndex) {
            this.zIndex = pars.zIndex;
        }
        else if (dys.zIndex >= 0) {
            this.zIndex = dys.zIndex;
        }

        var isIE6 = !-[1, ] && !window.XMLHttpRequest, html = document.getElementsByTagName('html')[0];
        if (isIE6 && document.body.currentStyle.backgroundAttachment !== 'fixed') {
            html.style.backgroundImage = 'url(about:blank)';
            html.style.backgroundAttachment = 'fixed';
        }
        ;
        var position = {
            fixed: isIE6 ? function (elem) {
                var style = elem.style,
                    dom = '(document.documentElement)',
                    left = parseInt(style.left) - document.documentElement.scrollLeft,
                    top = parseInt(style.top) - document.documentElement.scrollTop;
                this.absolute(elem);
                try {
                    style.setExpression('left', 'eval(' + dom + '.scrollLeft + ' + left + ') + "px"');
                    style.setExpression('top', 'eval(' + dom + '.scrollTop + ' + top + ') + "px"');
                } catch (err) {
                }
            } : function (elem) {
                elem.style.cssText = 'position:fixed !important;' + elem.style.cssText;
            }, absolute: isIE6 ? function (elem) {
                var style = elem.style;
                style.position = 'absolute';
                try {
                    style.removeExpression('left');
                    style.removeExpression('top');
                } catch (err) {
                }
            } : function (elem) {
                elem.style.position = 'absolute';
            }
        };

        var downX, downY;
        var nowWidth, nowHeight, nowPos;
        var reset1;
        var CMDiv;
        var _this = this;
        var focusText = null;
        if (pars.data != null) {
            this.data = pars.data;
        }
        if (pars.lock == null) {
            pars.lock = true;
        }
        if (pars.lock == true) {
            var t = 0, l = 0;
            if (isIE6) {
                t = document.documentElement.scrollTop;
                l = document.documentElement.scrollLeft;
            }
            this.full = document.createElement("div");
            this.fulliframe = document.createElement("iframe");
            this.fulliframe.setAttribute("frameBorder", "0");
            this.fulliframe.style.cssText = "left:" + l + "px;top:" + t + "px;width:100%;background:#000 !important;filter:Alpha(opacity=0);-moz-opacity:0;opacity:0;" + (this.zIndex >= 0 ? ("z-index:" + this.zIndex + ";") : "");

            var opacity = pars.opacity ? pars.opacity : 0.2;
            this.full.style.cssText = "width:100%;background:#000 !important;filter:Alpha(opacity=" + (opacity * 100) + ");-moz-opacity:" + opacity + ";opacity:" + opacity + ";left:" + l + "px;top:" + t + "px;" + (this.zIndex >= 0 ? ("z-index:" + this.zIndex + ";") : "");

            var temp = this.full.getElementsByTagName("iframe")[0];
            reset1 = function () {
                _this.full.style.width = document.documentElement.clientWidth + "px";
                _this.full.style.height = document.documentElement.clientHeight + "px";
                _this.fulliframe.style.width = document.documentElement.clientWidth + "px";
                _this.fulliframe.style.height = document.documentElement.clientHeight + "px";
            };
            reset1();
            position.fixed(this.fulliframe);
            position.fixed(this.full);
            document.body.appendChild(this.fulliframe);
            document.body.appendChild(this.full);
        }

        if (mode == "load") {
            var dia = $("<div class='dialogbox' style='width:16px;height:16px;'><div class='loading' style='width:16px;height:16px;'></div></div>");
            dia.appendTo("body");
            this.obj = dia[0];
        }

        if (mode != "load") {
            this.obj = document.createElement("table");
            var table = this.obj;
            document.body.appendChild(table);
            table.className = "dialogbox";
            table.setAttribute("cellSpacing", "0");
            table.setAttribute("cellPadding", "0");
            table.setAttribute("border", "0");
            if (this.zIndex >= 0) {
                table.style.cssText = "z-index:" + this.zIndex;
            }
            if (pars.id) {
                this.id = pars.id;
                eval("dys.dialog." + pars.id + "=this;");
                dys.dialog.array[dys.dialog.array.length] = this;
            }

            var tr = table.insertRow(0);
            var LT = tr.insertCell(0);
            LT.className = "LT";
            focusText = document.createElement("input");
            focusText.style.cssText = "border:0px;width:0px;height:1px;";
            LT.appendChild(focusText);

            var CT = tr.insertCell(1);
            CT.className = "CT";
            CT.onmousedown = function (e) {
                e = e || window.event;
                var target = window.event ? window.event.srcElement : e.target;
                if (target != this) {
                    return;
                }
                downX = e.clientX;
                downY = e.clientY;
                _this.moveMode = "move";
                if (!_this.CMDiv) {
                    _this.CMDiv = document.createElement("div");
                }
                _this.CMDiv.className = "CMDiv";
                _this.CMDiv.style.cssText = "width:" + CM.clientWidth + "px;height:" + CM.clientHeight + "px;left:" + (_this.leftWidth + 1) + "px;top:" + (_this.topHeight + 1) + "px;";
                table.rows[1].cells[1].appendChild(_this.CMDiv);
                document.body.style.cursor = "move";
            }
            //标题
            var title = document.createElement("div");
            title.className = "title";
            title.innerHTML = pars.title ? pars.title : (mode == "message" ? "消息框" : "标题");
            CT.appendChild(title);
            //按钮
            var btns = document.createElement("div");
            btns.className = "btns";
            CT.appendChild(btns);

            var RT = tr.insertCell(2);
            RT.className = "RT";

            tr = table.insertRow(1);
            var LM = tr.insertCell(0);
            LM.className = "LM";
            LM.innerHTML = "&nbsp;";

            var CM = tr.insertCell(1);
            CM.setAttribute("vAlign", "middle");
            CM.setAttribute("align", "center");
            CM.className = "CM";
            if (mode == "show") {
                CM.innerHTML = "<div style=\"padding:10px 15px;text-align:center;\">" + coru + "</div>";
            } else if (mode == "message") {
                CM.innerHTML = "<div" + (pars.iconsrc ? " style=\"background:url(" + pars.iconsrc + ") 20px 20px no-repeat;\"" : "") + " class=\"content" + (pars.icon ? " " + pars.icon : "") + "\">" + coru + "</div>";
            } else {
                CM.className = "CM loading";
                var iframe = document.createElement("iframe");
                iframe.frameBorder = "0";
                CM.appendChild(iframe);
                iframe.style.width = "100%";
                iframe.className = "hide";
                iframe.src = coru.indexOf("?") >= 0 ? coru + "&rn=" + Math.random() : coru + "?rn=" + Math.random();
                if (iframe.attachEvent) {
                    iframe.attachEvent("onload", function () {
                        iframe.className = "";
                        CM.className = "CM";
                        focusText.focus();
                    });
                }
                else {
                    iframe.onload = function () {
                        iframe.className = "";
                        CM.className = "CM";
                        focusText.focus();
                    };
                }
            }

            //加载按钮开始
            if (pars.buttons) {
                var boxbtns = document.createElement("div");
                boxbtns.className = "boxbtns";
                if ((typeof (pars.buttons) == "string" && pars.buttons == dys.dialog.buttons.OK) || (typeof (pars.buttons) != "string" && pars.buttons.length == 1)) {
                    boxbtns.style.cssText = "text-align:center;";
                }
                CM.appendChild(boxbtns);
                var enter = ['确定', '是', '保存'];
                var cancel = ['取消', '否'];
                var addbtn = function (text, func) {
                    var btn = document.createElement("input");
                    btn.type = "button";
                    for (var i = 0; i < enter.length; i++) {
                        if (enter[i] == text) {
                            btn.className = "enter";
                            break;
                        }
                    }
                    if (btn.className == "") {
                        for (var i = 0; i < cancel.length; i++) {
                            if (cancel[i] == text) {
                                btn.className = "cancel";
                                break;
                            }
                        }
                    }
                    btn.value = text;
                    btn.close = function () {
                        _this.close();
                    }
                    btn.onclick = func;
                    boxbtns.appendChild(btn);
                    btnFocus = btn;
                };
                if (typeof (pars.buttons) == "string") {
                    if (pars.buttons == dys.dialog.buttons.OK) {
                        addbtn("确定", function () {
                            if (_this.pars.ok) {
                                _this.pars.close = function () {
                                    _this.close();
                                };
                                _this.pars.ok();
                            }
                            _this.close();
                        });
                    } else if (pars.buttons == dys.dialog.buttons.OKCancel) {
                        addbtn("确定", function () {
                            if (_this.pars.ok) {
                                _this.pars.close = function () {
                                    _this.close();
                                };
                                _this.pars.ok();
                            }
                        });
                        addbtn("取消", function () {
                            if (_this.pars.cancel) {
                                _this.pars.cancel();
                            }
                            _this.close();
                        });
                    } else if (pars.buttons == dys.dialog.buttons.saveCancel) {
                        addbtn("保存", function () {
                            if (_this.pars.save) {
                                _this.pars.close = function () {
                                    _this.close();
                                };
                                _this.pars.save(_this);
                            }
                        });
                        addbtn("取消", function () {
                            if (_this.pars.cancel) {
                                _this.pars.cancel();
                            }
                            _this.close();
                        });
                    } else if (pars.buttons == dys.dialog.buttons.yesNo) {
                        addbtn("是", function () {
                            if (_this.pars.yes) {
                                _this.pars.close = function () {
                                    _this.close();
                                };
                                _this.pars.yes();
                            }
                        });
                        addbtn("否", function () {
                            if (_this.pars.no) {
                                _this.pars.close = function () {
                                    _this.close();
                                };
                                _this.pars.no();
                            }
                        });
                    }
                } else {
                    for (var i = 0; i < pars.buttons.length; i++) {
                        addbtn(pars.buttons[i].text, pars.buttons[i].click);
                    }
                }
            }
            //加载按钮结束
            if (pars.height) {
                if (typeof (pars.height) == "number") {
                    CM.style.height = pars.height + "px";
                } else {
                    CM.style.height = pars.height;
                }
            }
            var RM = tr.insertCell(2);
            RM.className = "RM";
            RM.innerHTML = "&nbsp;";
            tr = table.insertRow(2);

            var LB = tr.insertCell(0);
            LB.className = "LB";
            var CB = tr.insertCell(1);
            CB.className = "CB";
            var RB = tr.insertCell(2);
            RB.className = "RB";
            RB.onmousedown = function (e) {
                e = e || window.event;
                downX = e.clientX;
                downY = e.clientY;
                _this.moveMode = "resize";
                if (!_this.CMDiv) {
                    _this.CMDiv = document.createElement("div");
                }
                _this.CMDiv.className = "CMDiv";
                _this.CMDiv.style.cssText = "width:" + CM.clientWidth + "px;height:" + CM.clientHeight + "px;left:" + (_this.leftWidth + 1) + "px;top:" + (_this.topHeight + 1) + "px;";
                table.rows[1].cells[1].appendChild(_this.CMDiv);
                document.body.style.cursor = "se-resize";
            };
        }

        var reset2 = function () {
            if (isIE6) {
                _this.obj.style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight / 2 - _this.obj.clientHeight / 2) + "px";
                _this.obj.style.left = document.documentElement.scrollLeft + (document.documentElement.clientWidth / 2 - _this.obj.clientWidth / 2) + "px";
            } else {
                _this.obj.style.top = (document.documentElement.clientHeight / 2 - _this.obj.clientHeight / 2) + "px";
                _this.obj.style.left = (document.documentElement.clientWidth / 2 - _this.obj.clientWidth / 2) + "px";
            }
        };

        if (mode != "load") {
            var mousemove = function (e) {
                e = e || window.event;
                if (_this.moveMode == "resize" && mode != "show" && mode != "message") {//调整大小  不支持消息模式
                    var width = table.clientWidth + (e.clientX - downX) * 2;
                    var height = table.clientHeight + (e.clientY - downY) * 2;
                    var changesize = false;
                    if (width - (_this.leftWidth + _this.rightWidth) * 2 >= _this.minWidth) { //调整宽度
                        table.style.width = width + "px";
                        CM.style.width = width - _this.leftWidth - _this.rightWidth - 2 + "px";
                        _this.CMDiv.style.width = CM.clientWidth + "px";
                        downX = e.clientX;
                        changesize = true;
                    }
                    if (height - (_this.topHeight + _this.bottomHeight) * 2 >= _this.minHeight) {//调整高度
                        table.style.height = height + "px";
                        CM.style.height = height - _this.topHeight - _this.bottomHeight - 23 + "px";
                        _this.CMDiv.style.height = CM.clientHeight + "px";
                        iframe.style.height = height - _this.topHeight - (_this.pars.buttons ? 36 : 0) - _this.bottomHeight - 2 + "px";
                        downY = e.clientY;
                        changesize = true;
                    }
                    if (changesize == true) {
                        reset2();
                    }
                } else if (_this.moveMode == "move") {//移动窗体
                    function absPos(_node, parentNode) {
                        var x = y = 0;
                        var node = _node;
                        do {
                            if (parentNode && node == parentNode) {
                                break;
                            }
                            x += node.offsetLeft;
                            y += node.offsetTop;
                        } while (node = node.offsetParent);
                        node = _node;
                        return { 'x': x, 'y': y };
                    }

                    var pos = absPos(table);
                    table.style.left = pos.x + (e.clientX - downX) + "px";
                    table.style.top = pos.y + (e.clientY - downY) + "px";

                    downX = e.clientX;
                    downY = e.clientY;
                }
            };
            table.onmousemove = mousemove;
            if (this.full) {
                this.full.onmousemove = mousemove;
            }
            var mouseup = function (e) {
                _this.moveMode = "";
                document.body.style.cursor = "";
                if (_this.CMDiv && _this.CMDiv.parentNode) {
                    _this.CMDiv.parentNode.removeChild(_this.CMDiv);
                }
            }
            table.onmouseup = mouseup;
            if (pars.width) {
                table.style.width = typeof (pars.width) == "number" ? pars.width + "px" : pars.width;
            }
            if (pars.height) {
                var height = parseInt(pars.height) - CT.clientHeight - CB.clientHeight - 2;
                this.topHeight = CT.clientHeight;
                this.bottomHeight = CB.clientHeight;
                this.leftWidth = LM.clientWidth;
                this.rightWidth = RM.clientWidth;
                LM.style.width = LM.clientWidth + "px";
                RM.style.width = RM.clientWidth + "px";
                CM.style.height = height + "px";
                if (mode != "show" && mode != "message") {
                    iframe.style.height = (height - (pars.buttons ? 36 : 0)) + "px";
                }
                table.style.height = typeof (pars.height) == "number" ? pars.height + "px" : pars.height;
            }
            if (table.clientWidth < 200) {
                table.style.width = "200px";
            }
        }
        reset2();
        position.fixed(this.obj);
        if (this.full) {
            if (mode != "load") {
                this.full.onmouseup = mouseup;
            }
            this.full.onclick = function () {
                reset2();
            };
            this.full.ondblclick = function () {
                _this.close();
            };
        }
        $(window).resize(function () {
            if (reset1) {
                reset1();
            }
            reset2();
        });

        if (mode == "show") {
            var widthtemp = CM.getElementsByTagName("div")[0].offsetWidth;
            this.minWidth = widthtemp < 200 ? 200 : widthtemp;
            this.minHeight = CM.getElementsByTagName("div")[0].offsetHeight;
        }

        if (mode == "open") {
            //刷新按钮
            if (pars.refresh == null) {
                pars.refresh = false;
            }
            if (pars.refresh == true) {
                var shuaxin = document.createElement("a");
                shuaxin.className = "shuaxin";
                shuaxin.href = "javascript:;";
                shuaxin.onclick = function () {
                    CM.className = "CM loading";
                    var iframe = CM.getElementsByTagName("iframe")[0];
                    iframe.className = "hide";
                    iframe.src = coru.indexOf("?") >= 0 ? coru + "&rn=" + Math.random() : coru + "?rn=" + Math.random();
                    if (iframe.attachEvent) {
                        iframe.attachEvent("onload", function () {
                            iframe.className = "";
                            CM.className = "CM";
                            focusText.focus();
                        });
                    }
                    else {
                        iframe.onload = function () {
                            iframe.className = "";
                            CM.className = "CM";
                            focusText.focus();
                        };
                    }
                    return false;
                }
                shuaxin.onfocus = function () {
                    this.blur();
                }
                btns.appendChild(shuaxin);
            }
            //最大化按钮
            if (pars.max == null) {
                pars.max = false;
            }
            if (pars.max == true) {
                var max = document.createElement("a");
                max.className = "max";
                max.href = "javascript:;";
                max.onclick = function () {
                    if (this.className == "max") {
                        nowWidth = table.clientWidth;
                        nowHeight = table.clientHeight;
                        nowPos = $(table).offset();
                        table.style.left = "0px";
                        table.style.top = "0px";
                        table.style.width = document.documentElement.clientWidth + "px";
                        table.style.height = document.documentElement.clientHeight + "px";
                        CM.style.height = document.documentElement.clientHeight - _this.topHeight - _this.bottomHeight - 23 + "px";
                        CM.style.width = document.documentElement.clientWidth - _this.leftWidth - _this.rightWidth - 2 + "px";
                        if (mode != "show") {
                            CM.getElementsByTagName("iframe")[0].style.height = document.documentElement.clientHeight - _this.topHeight - _this.bottomHeight - 2 + "px";
                        }
                        this.className = "max2";
                    } else {
                        table.style.left = nowPos.left + "px";
                        table.style.top = nowPos.top + "px";
                        table.style.width = nowWidth + "px";
                        table.style.height = nowHeight + "px";
                        CM.style.height = nowHeight - _this.topHeight - _this.bottomHeight - 23 + "px";
                        CM.style.width = nowWidth - _this.leftWidth - _this.rightWidth - 2 + "px";
                        if (mode != "show") {
                            CM.getElementsByTagName("iframe")[0].style.height = nowHeight - _this.topHeight - _this.bottomHeight - 2 + "px";
                        }
                        this.className = "max";
                    }
                    return false;
                }
                max.onfocus = function () {
                    this.blur();
                }
                btns.appendChild(max);
            }
        }

        if (mode != "load") {//关闭按钮
            var closebtn = document.createElement("a");
            closebtn.className = "close";
            closebtn.href = "javascript:;";
            closebtn.onclick = function () {
                _this.data = null;
                _this.close();
                return false;
            }
            closebtn.onfocus = function () {
                this.blur();
            }
            btns.appendChild(closebtn);
        }

        if (mode != "load") {
            if (_this.CMDiv) {
                _this.CMDiv.onselectstart = function () {
                    return false;
                };
            }
            LT.onselectstart = function () {
                return false;
            };
            CT.onselectstart = function () {
                return false;
            };
            CT.setAttribute("unselectable", "on");
            RT.onselectstart = function () {
                return false;
            };
            LM.onselectstart = function () {
                return false;
            };
            RM.onselectstart = function () {
                return false;
            };
            LB.onselectstart = function () {
                return false;
            };
            CB.onselectstart = function () {
                return false;
            };
            RB.onselectstart = function () {
                return false;
            };
        }
        if (this.full) {
            this.full.onselectstart = function () {
                return false;
            };
        }

        if (btnFocus) {
            btnFocus.focus();
        }
    },
    //弹出框
    dialog: {
        show: function (context, pars) {
            return new dys.dialogBox(context, pars, "show");
        },
        message: function (context, pars) {
            return new dys.dialogBox(context, pars, "message");
        },
        open: function (url, pars) {
            return new dys.dialogBox(url, pars, "open");
        },
        load: function (pars) {
            return new dys.dialogBox("", pars, "load");
        },
        alert: function (context, pars) {
            if (!pars) {
                pars = {};
            }
            if (!pars.buttons) {
                pars.buttons = dys.dialog.buttons.OK;
            }
            return new dys.dialogBox(context, pars, "message");
        },
        confirm: function (context, pars) {
            if (!pars.icon) {
                pars.icon = dys.dialog.icon.question;
            }
            if (!pars.buttons) {
                pars.buttons = dys.dialog.buttons.OKCancel;
            }
            return new dys.dialogBox(context, pars, "message");
        },
        buttons: { OKCancel: 'OKCancel', yesNo: 'yesNo', OK: 'OK', saveCancel: 'saveCancel' },
        icon: { error: 'error', warning: 'warning', question: 'question', success: 'success' },
        get: function (id) {
            for (var d = 0; d < dys.dialog.array.length; d++) {
                if (dys.dialog.array[d].id == id) {
                    return dys.dialog.array[d];
                }
            }
        },
        array: []
    },
    //文本框控件
    textBox: function (conid, pars) {
        this.control = $("#" + conid);
        this.id = conid;
        this.type = "dys.textBox";
        var name = name != null ? name : conid;

        this.enable = this.control.attr("disabled") == "disabled" ? false : true;
        this.text = this.control.length == 0 ? "" : this.control.val();
        this.multiLine = false;
        this.style = {};
        this.minLength = 0;
        this.maxLength = 4000;
        this.min = -2147483647;
        this.max = 2147483647;
        this.notNull = false;
        this.dataType = "text";
        this.message = "";
        if (pars != null) {
            if (pars.text != null) {
                this.text = pars.text;
            }
            if (pars.multiLine != null) {
                this.multiLine = pars.multiLine;
            }
            if (pars.style != null) {
                this.style = pars.style;
            }
            if (pars.minLength != null) {
                this.minLength = pars.minLength;
            }
            if (pars.maxLength != null) {
                this.maxLength = pars.maxLength;
            }
            if (pars.min != null) {
                this.min = pars.min;
            }
            if (pars.max != null) {
                this.max = pars.max;
            }
            if (pars.notNull != null) {
                this.notNull = pars.notNull;
            }
            if (pars.dataType != null) {
                this.dataType = pars.dataType;
            }
            if (pars.message != null) {
                this.message = pars.message;
            }

            if (pars.changed != null) {
                if (typeof (pars.changed) == "string") {
                    eval("this.changed = " + pars.changed + ";");
                } else {
                    this.changed = pars.changed;
                }
            }
            if (pars.changing != null) {
                if (typeof (pars.changing) == "string") {
                    eval("this.changing = " + pars.changing + ";");
                } else {
                    this.changing = pars.changing;
                }
            }
        }

        if (this.control.length == 0) {
            var strstyle = "";
            var txtstyle = "";
            for (var item in this.style) {
                if (item != "width") {
                    txtstyle += item + ":" + this.style[item];
                }
                strstyle += item + ":" + this.style[item];
                if (item == "width" || item == "height") {
                    if (!isNaN(this.style[item])) {
                        strstyle += "px;";
                        if (item != "width") {
                            txtstyle += "px;";
                        }
                    }
                }
            }
            strstyle = strstyle != "" ? " style=\"" + strstyle + "\"" : ""
            txtstyle = txtstyle != "" ? " style=\"" + txtstyle + "\"" : ""

            if (this.multiLine == true) {
                this.control = $("<div class=\"textbox\"" + strstyle + " conid=" + conid + "><div class=\"main\"><textarea name=\"" + name + "\" rows=\"2\" cols=\"20\"" + txtstyle + " id=\"" + conid + "\">" + this.text + "</textarea><a></a></div></div>").find("textarea");
            } else {
                this.control = $("<div class=\"textbox\"" + strstyle + " conid=" + conid + "><div class=\"main\"><input name=\"" + name + "\" type=\"text\"" + txtstyle + " value=\"" + this.text + "\" id=\"" + conid + "\" /><a></a></div></div>").find("input");
            }
        }

        this.ref();
        dys.append(this);
    },
    checkradiofunc: { //checkbox,radiobutton公共事件
        over: function () {
            var input = $(this).children("input").eq(0);
            if (input.prop("checked")) {
                $(this).removeClass("hover").removeClass("checked").addClass("checkedhover");
            } else {
                $(this).removeClass("checkedhover").removeClass("checked").addClass("hover");
            }
        }, out: function () {
            var input = $(this).children("input").eq(0);
            if (input.prop("checked")) {
                $(this).removeClass("hover").removeClass("checkedhover").addClass("checked");
            } else {
                $(this).removeClass("checkedhover").removeClass("checked").removeClass("hover");
            }
        }
    },
    //文本数据类型
    dataType: { text: 'text', number: 'number', int: 'int', double: 'double', phoneNumber: 'phonenumber', email: 'email', cradId: 'cradid', url: 'url', ip: 'ip' },
    ajaxGridRow: function () {
        this.cells = [];
    },
    //列表控件 
    ajaxGrid: function (conid, pagesize, paging, title, offsetHeight, base64str) {
        this.checkedRows = [];
        this.selectedRow = null;
        this.conId = conid; //控件ID
        this.pageSize = pagesize; //一页显示多少条
        this.pageIndex = 0; //第几页
        this.pageCount = 0; //共几页
        this.savestate = false;
        this.allowPaging = paging; //是否分页
        this.defaultTitle = title; //导出对话框默认标题
        this.base64str = base64str;
        this.sortField = null;
        this.orderby = "";
        this.filterdiv = null;
        this.filterField = null;
        this.offsetHeight = offsetHeight;
        this.offsetMode = null;
        this.where = "";
        this.type = "dys.ajaxGrid";
        var _this = this;

        this.maindiv = $("#" + conid);
        this.dataheaderdiv = this.maindiv.children(".dataheader");
        this.datadiv = this.maindiv.children(".data");
        this.bottomdiv = this.maindiv.children(".bottom");
        this.headdiv = this.dataheaderdiv.children(":first");
        this.headwidth = this.headdiv.width();
        this.fullback = this.maindiv.children(".fullback");
        this.whereHidden = null;
        this.fieldHidden = null;
        var height = this.maindiv.height();
        if (offsetHeight == 0) {
            if (height > 0) {
                this.height(height);
            }
        } else {
            this.height($(window).height() + offsetHeight);
        }

        this.maindiv.children("input").each(function () {
            if (this.id.indexOf("whereHidden") >= 0) {
                _this.whereHidden = $(this);
            } else if (this.id.indexOf("fieldHidden") >= 0) {
                _this.fieldHidden = $(this);
            }
        });

        //初始化页码开始
        var pre = this.bottomdiv.find(".pre").click(function () {
            if ($(this).attr("disabled") == "disabled") {
                return;
            }
            _this.pageIndex--;
            _this.load();
        }).focus(function () {
            $(this).blur();
            return;
        });
        var next = pre.siblings(".next").click(function () {
            if ($(this).attr("disabled") == "disabled") {
                return;
            }
            _this.pageIndex++;
            _this.load();
        }).focus(function () {
            $(this).blur();
            return;
        });
        var page = next.siblings(".pagecount").children("input");
        var gopage = function () {
            _this.pageIndex = Number(page.val()) - 1;
            if (_this.pageIndex < 0) {
                _this.pageIndex = 0;
            }
            if (_this.pageIndex >= _this.pageCount) {
                _this.pageIndex = _this.pageCount - 1;
            }
            _this.load();
            page.blur();
            return false;
        };
        page.focus(function () {
            $(this).addClass("focus").select().siblings("a").show();
        }).blur(function () {
            setTimeout(function () {
                page.removeClass("focus").val(_this.pageIndex + 1).siblings("a").hide();
            }, 200);
        }).keydown(function (event) {
            if (event.which == 13) {
                return gopage();
            }
        });
        page.siblings("a").click(function () {
            return gopage();
        });

        //判断筛选位置
        var getfilterpos = function (left, headwidth) {
            if (_this.filterdiv == null) {
                return;
            }
            if (left + 222 > _this.datadiv.width()) {
                return left - 222 + headwidth;
            } else {
                return left;
            }
        };
        //当滚动条滚动时
        this.datadiv.scroll(function () {
            _this.dataheaderdiv.scrollLeft($(this).scrollLeft());
            $(this).children(".databtns").scrollTop($(this).scrollTop());

            if (_this.filterdiv && _this.filterdiv.is(":visible")) {
                _this.filterdiv.css({ left: getfilterpos(parseInt(_this.filterdiv.attr("left")) - $(this).scrollLeft(), parseInt(_this.filterField.width())) });
            }
        });
        var values, notin; //缓存筛选属性
        var fields = "";
        //排序
        this.headdiv.children("div").click(function () {
            if ($(this).hasClass("checkbox")) {
                $(this).addClass("checked");
                return;
            }
            if ($(this).hasClass("full")) {
                return;
            }
            var order = $(this).hasClass("asc") ? "desc" : "asc";
            var field = $(this).attr("field");
            _this.orderby = "to_number(decode(isNumber(" + field + "),1," + field + ",null)) " + order + "," + field + " " + order;
            _this.load();
            if (_this.sortField != null) {
                _this.sortField.removeAttr("class");
            }
            $(this).attr("class", order);
            _this.sortField = $(this);
        }).each(function () {
            var f = $(this).attr("field");
            var tx = $(this).children("span").html();
            if (tx == null || tx == "" || f == "" || f == null) return;
            fields += (fields == "" ? "" : ",") + f + (tx == f ? "" : " \"" + $(this).children("span").html() + "\"");
        }).children("a").focus(function () {
            $(this).blur();
            return false;
        }).click(function (event) {
            //筛选按钮
            event.stopPropagation();
            var gjz = "";
            values = $(this).parent().attr("values");
            notin = $(this).parent().attr("notin");
            if (_this.filterdiv == null) {
                var dropitem = "<a href='javascript:;' ysf='='>等于</a>"
                    + "<a href='javascript:;' ysf='<>'>不等于</a>"
                    + "<a href='javascript:;' ysf='>'>大于</a>"
                    + "<a href='javascript:;' ysf='>='>大于等于</a>"
                    + "<a href='javascript:;' ysf='<'>小于</a>"
                    + "<a href='javascript:;' ysf='<='>小于等于</a>"
                    + "<a href='javascript:;' ysf='likeL'>开头是</a>"
                    + "<a href='javascript:;' ysf='likeR'>结尾是</a>"
                    + "<a href='javascript:;' ysf='like'>包含</a>"
                    + "<a href='javascript:;' ysf='not like'>不包含</a>";
                _this.filterdiv = $("<div class='filterdiv'><div class='search'><input type='text' /><a href='javascript:;'></a><span class='checkbox'>全选</span></div>"
                    + "<div class='list load'>&nbsp;</div>"
                    + "<div class='term'><div class='drop'>包含</div><input type='text' /></div>"
                    + "<div class='btns'><a href='javascript:;' class='clear'>清除筛选</a><a href='javascript:;' class='close'>关闭</a><a href='javascript:;' class='enter'>确定</a></div>"
                    + "<div class='dropitem' style='display:none;'>" + dropitem + "</div></div>").click(function (event) {
                    event.stopPropagation();
                }).hide().insertBefore(_this.bottomdiv);
                //初始化搜索
                var check = _this.filterdiv.find(".search span").click(function () {
                    if ($(this).hasClass("checked")) {
                        $(this).removeClass("checked");
                    } else {
                        $(this).addClass("checked");
                    }
                    var ck = $(this).hasClass("checked");
                    if ($(this).siblings("input").val() != "") {
                        list.children("a").each(function () {
                            if (ck == !$(this).hasClass("checked")) {
                                $(this).click();
                            }
                        });
                        return;
                    }
                    if (!ck) {
                        _this.filterField.attr("notin", "in");
                        list.children("a").removeClass("checked");
                    } else {
                        _this.filterField.attr("notin", "not in");
                        list.children("a").addClass("checked");
                    }
                    _this.filterField.attr("values", "");
                });
                check.siblings("input").keyup(function () {
                    if (gjz != $(this).val()) {
                        gjz = $(this).val();
                        _this.filterdiv.children(".list").html("");
                        _this.loadFilterItems(gjz);

                        if (check.hasClass("checked") != (_this.filterField.attr("notin") == "not in")) {
                            if (_this.filterField.attr("notin") == "not in") {
                                check.addClass("checked");
                            } else {
                                check.removeClass("checked");
                            }
                        }
                    }
                }).siblings("a").focus(function () {
                    this.blur();
                }).click(function () {
                    $(this).siblings("input").val("").keyup();
                });
                //初始化条件筛选
                var drop = _this.filterdiv.children(".term").children(".drop").click(function () {
                    var ysfx = _this.filterField.attr("ysf");
                    if (ysfx == null) {
                        ysfx = "like";
                    }
                    _this.filterdiv.children(".dropitem").children().each(function () {
                        if ($(this).attr("ysf") == ysfx) {
                            $(this).addClass("sel");
                        }
                        else {
                            $(this).removeClass("sel");
                        }
                    })
                    _this.filterdiv.children(".dropitem").show();
                });
                _this.filterdiv.children(".dropitem").children().focus(function () {
                    this.blur();
                }).click(function () {
                    drop.html($(this).html());
                    _this.filterField.attr("ysf", $(this).attr("ysf"));
                    $(this).parent().hide();
                });
                var termstr = "";
                drop.siblings("input").keyup(function () {
                    if (termstr != $(this).val()) {
                        termstr = $(this).val();
                        if (termstr == "") {
                            _this.filterField.removeAttr("gjz");
                        }
                        else {
                            _this.filterField.attr("gjz", termstr);
                        }
                    }
                });

                //初始化按钮
                var btns = _this.filterdiv.children(".btns");
                ;
                btns.children("a").focus(function () {
                    this.blur();
                });
                btns.children(".clear").click(function () {
                    _this.filterField.removeAttr("values");
                    _this.filterField.removeAttr("notin");
                    _this.filterdiv.hide();
                    _this.refwhere();
                }).siblings(".close").click(function () {
                    if (values != null) {
                        _this.filterField.attr("values", values);
                    } else {
                        _this.filterField.removeAttr("values");
                    }
                    if (notin != null) {
                        _this.filterField.attr("notin", notin);
                    } else {
                        _this.filterField.removeAttr("notin");
                    }
                    _this.filterdiv.hide();
                }).siblings(".enter").click(function () {
                    _this.refwhere();
                    _this.filterdiv.hide();
                });
            }

            var pos = $(this).parent().position();
            _this.filterField = $(this).parent();
            var list = _this.filterdiv.css({
                left: getfilterpos(pos.left, $(this).parent().width()),
                top: pos.top + 69,
                height: 0
            }).attr("left", pos.left + _this.datadiv.scrollLeft()).show().animate({
                height: 276
            }).children(".list").html("");

            var checkall = list.siblings(".search").children("input").val("").siblings("span");
            if ($(this).parent().attr("notin") == "not in") {
                checkall.addClass("checked");
            } else {
                checkall.removeClass("checked");
            }
            var ysfmc = list.siblings(".dropitem").hide().children("[ysf='" + _this.filterField.attr("ysf") + "']").html();
            if (ysfmc == null) {
                ysfmc = "包含";
            }
            list.siblings(".term").children(".drop").html(ysfmc);
            _this.loadFilterItems("");
        });
        _this.fieldHidden.val(fields);

        this.load();

        $(window).resize(function () {
            _this.resetsize();
        });
        $(document).click(function () {
            if (_this.filterdiv) _this.filterdiv.hide();
        });
    },
    //控件提示信息
    tooltip: { obj: function (text, conid) {
        this.controlId = conid;
        this.text = text;
        this.control = $("<div class='tooltip'><span>" + text + "</span><i></i></div>").appendTo("body");
        this.timer = null;
    }, show: function (text, conid) {
        var tip = null;
        var index = -1;
        for (var d = 0; d < dys.tooltip.tips.length; d++) {
            if (dys.tooltip.tips[d].controlId == conid) {
                tip = dys.tooltip.tips[d];
                index = d;
                break;
            }
        }
        if (tip == null) {
            tip = new dys.tooltip.obj(text, conid);
            index = dys.tooltip.tips.length;
            dys.tooltip.tips[dys.tooltip.tips.length] = tip;
        } else {
            window.clearTimeout(tip.timer);
        }

        var pos = dys.get(conid).get().offset();
        tip.control.css({ left: pos.left + "px", top: pos.top - 27 + "px" }).show();
        var hide = function () {
            tip.control.fadeOut(500, function () {
                window.clearInterval(tip.timer);
            });
        };
        tip.timer = setTimeout(hide, 3000);
        tip.control.click(hide);
    }, tips: []
    },
    validates: {
        isCardId: function () {
        },
        isEmail: function () {
        },
        isUrl: function () {
        },
        isIp: function () {
        },
        isPhone: function () {
        }
    },
    //所有控件集合
    controls: [],
    //根据ID获取控件
    get: function (id) {
        for (var d = 0; d < dys.controls.length; d++) {
            if (dys.controls[d].id == id) {
                return dys.controls[d];
            }
        }
    },
    append: function (obj) {
        for (var d = 0; d < dys.controls.length; d++) {
            if (dys.controls[d].id == obj.id) {
                dys.controls.splice(d, 1);
                break;
            }
        }
        dys.controls[dys.controls.length] = obj;
    },
    zIndex: 10000
};

dys.dateTimePicker.prototype.setLocation = function () {
    var x = this.maindiv.offset().left + 1;
    var y = this.maindiv.offset().top + this.maindiv.height() + 2;
    if (x + this.calendar.maindiv.width() > $(top.document).width()) {
        x = x - (this.calendar.maindiv.width() - this.maindiv.width());
    }
    var calheight = Number(this.calendar.maindiv.attr("height"));
    if (y + calheight > $(top.document).height()) {
        y = y - this.maindiv.height() - calheight - 2;
        if ($.browser.msie && $.browser.version == 6.0) {
            y++;
        }
    } else {
        if ($.browser.msie && $.browser.version == 6.0) {
            y--;
        }
    }

    var par = window;
    while (true) {
        var fsx = par.parent.$("iframe");
        for (var i = 0; i < fsx.length; i++) {
            if (fsx[i].contentWindow == par) {
                var t = $(fsx[i]);
                var off = t.offset();
                var docu = $(fsx[i].contentWindow.document);
                x += off.left - docu.scrollLeft();
                y += off.top - docu.scrollTop();
            }
        }
        if (par.parent == top) {
            break;
        }
        par = par.parent;
    }

    this.calendar.show(x, y);
};

//日期方法
dys.calendar.prototype.initcdate = function (type) {
    var _this = this;
    this.maindiv.children(".caldate").find("a").click(function (event) {
        event.stopPropagation();
        if ($(this).hasClass("e")) {
            var m = Number($(this).attr("m"));
            _this.dateTime.setDate(Number($(this).html()));
            _this.create(m >= 0 ? "rightm" : "leftm");
        } else {
            $(this).siblings(".c").removeClass("c");
            $(this).addClass("c");
            _this.dateTime.setDate(parseInt($(this).html()));
            if (_this.picker) {
                if (_this.format_sta.indexOf("HH") < 0) {
                    _this.maindiv.remove();
                }
            }
            _this.changed();
        }
    });
};
//创建具体日期
dys.calendar.prototype.create = function (type) {
    var _this = this;
    var year = this.dateTime.getFullYear();
    var month = this.dateTime.getMonth();
    var date = this.dateTime.getDate();
    if (type == "lefty") {
        year--;
    }
    else if (type == "leftm") {
        month--;
    }
    else if (type == "righty") {
        year++;
    }
    else if (type == "rightm") {
        month++;
    }

    var dc = new Date();
    var dt = new Date(year, month, date);
    var d = new Date(year, month, 1);
    d.setDate(1 - d.getDay());
    var html = "";
    for (var i = 0; i < 42; i++) {
        var str = "";
        if (d.getFullYear() == dt.getFullYear() && d.getMonth() == dt.getMonth() && d.getDate() == dt.getDate()) {
            str = " class=\"c\"";
        }
        else if (d.getMonth() != dt.getMonth()) {
            str = " class=\"e\" m=\"" + (d > dt ? 1 : -1) + "\"";
        }
        if (d.getDay() == 0) {
            if (str == "") {
                str = " class=\"s\"";
            }
            else {
                str = str.replace("=\"", "=\"s ");
            }
        }
        if (dc.getFullYear() == dt.getFullYear() && d.getMonth() == dc.getMonth() && d.getDate() == dc.getDate()) {
            if (str == "") {
                str = " class=\"dc\"";
            }
            else {
                str = str.replace("=\"", "=\"dc ");
            }
        }

        html += "<a href=\"javascript:;\" onfocus=\"this.blur();\"" + str + ">" + d.getDate() + "</a>";
        d.setDate(d.getDate() + 1);
    }

    if (!type || type == "") {
        this.maindiv.find(".caldate div").html(html);
        _this.initcdate();
    } else {
        var cdate = this.maindiv.children(".caldate").css({ position: "relative" });
        cdate.children("div").css({
            position: "absolute",
            width: cdate.width(),
            left: 12
        }).animate({
            left: type.indexOf("left") >= 0 ? cdate.width() : 0 - cdate.width() + 12
        }, 200);

        $("<div>" + html + "</div>").css({
            position: "absolute",
            left: type.indexOf("left") >= 0 ? 0 - cdate.width() : cdate.width(),
            width: cdate.width()
        }).appendTo(cdate).animate({
            left: 12
        }, 200, function () {
            $(this).removeAttr("style").siblings().remove();
            cdate.removeAttr("style");
            _this.initcdate();
        });
    }
    this.dateTime.setFullYear(year);
    this.dateTime.setMonth(month);
    var as = this.maindiv.find(".calhead span a");
    as.eq(0).html(this.dateTime.getFullYear() + "年");
    as.eq(1).html($.lpad(this.dateTime.getMonth() + 1, 2, "0") + "月");
    this.changed();
};
dys.calendar.prototype.toformat = function (date) {
    var t = date;
    if (!date) {
        t = this.dateTime;
    }
    var value = this.format.replace("yyyy", t.getFullYear()).replace("MM", $.lpad(t.getMonth() + 1, 2, '0')).replace("dd", $.lpad(t.getDate(), 2, '0'));
    this.value = value.replace("HH", $.lpad(t.getHours(), 2, "0")).replace("mm", $.lpad(t.getMinutes(), 2, "0")).replace("ss", $.lpad(t.getSeconds(), 2, "0"));
    if (this.maintxt) {
        this.maintxt.val(this.value);
    }
    return this.value;
};
dys.calendar.prototype.show = function (x, y) {
    var y1 = y2 = y;
    var calheight = Number(this.maindiv.attr("height"));
    var div = $("#" + this.maindiv.attr("maintxt")).parent();
    if (y < div.offset().top) {
        y1 = y + calheight;
    }
    this.maindiv.css({
        position: "absolute",
        display: "",
        left: x,
        top: y1,
        height: 0
    }).animate({
        height: Number(this.maindiv.attr("height")),
        top: y2
    }, 200);
};
dys.calendar.prototype.changed = function () {
    this.toformat();
    if (this.dateTimeChanged) {
        this.dateTimeChanged(this.dateTime, this.value);
    }
};
//日期事件
dys.calendar.prototype.dateTimeChanged = function (date, strdate) {
};
dys.calendar.prototype.ref = function () {

}

//下拉菜单方法
dys.dropList.changed = function (value) {
}
dys.dropList.prototype.initstyle = function () {
    var widthx = this.maindiv.children(".main").width() + 14; //计算宽度
    var count = this.droplistdiv.children(".dropmain").children("table")[0].rows.length;
    if (count > this.itemcount) {
        count = this.itemcount;
    }
    if (count < 3) {
        count = 3;
    }
    var heightx = 22 * count; //计算高度
    var linkh = heightx / 2 - 30; //link的位置
    if (linkh < 0) {
        linkh = 0;
    }

    this.droplistdiv.css({
        width: widthx,
        height: heightx + 4
    }).children(".splitwhite").css({
        width: widthx - 2
    }).siblings(".dropmain").css({
        width: widthx - 4,
        height: heightx
    }).siblings(".link").css({
        top: linkh
    });
};
dys.dropList.prototype.show = function () {
    var offset = this.maindiv.offset();
    var x = offset.left;
    var y = offset.top + this.maintxt.height() + 1;

    var par = window;
    var isframe = false;
    while (true) {
        var fsx = par.parent.$("iframe");
        for (var i = 0; i < fsx.length; i++) {
            if (fsx[i].contentWindow == par) {
                var t = $(fsx[i]);
                var off = t.offset();
                var docu = $(fsx[i].contentWindow.document);
                x += off.left - docu.scrollLeft();
                y += off.top - docu.scrollTop();
                isframe = true;
            }
        }
        if (par.parent == top) {
            break;
        }
        par = par.parent;
    }
    //if (isframe) { x += 1; }

    this.droplistdiv.css({ display: "", left: x, top: y });
    var widthx = this.maintable.width();
    if (widthx > this.droplistdiv.width()) {
        if (widthx > 400) {
            widthx = 400;
        }
        this.droplistdiv.width(widthx + 4).children(".dropmain").width(widthx);
    }
    if (this.niceScroll) {
        this.niceScroll.show();
        this.niceScroll.resize();
    }
};
dys.dropList.prototype.get = function () {
    return this.control;
};
dys.dropList.prototype.add = function (text, value, selected, second) {
    var html = "<tr value='" + value + "'>";
    if (this.multiple) {
        html += "<td class='c'><span></span></td>";
    }
    html += "<td class='m'>" + text + "</td>";
    if (second == null) {
        second = "";
    }
    var ts = second.split(",");
    if (this.seCount < 0) {
        this.seCount = ts.length;
    }
    for (var j = 0; j < this.seCount; j++) {
        html += "<td>" + (j >= ts.length ? "&nbsp;" : ts[j]) + "</td>";
    }
    html += "</tr>";
    var tr = $(html);
    tr.appendTo(this.maintable);
    tr.mouseover(function () {
        $(this).addClass("hover");
    }).mouseout(function () {
        $(this).removeClass("hover");
    }).click(this.itemClick);
    if (selected == true) {
        tr.click();
    }
};
dys.dropList.prototype.ref = function () {
    var _this = this;
    this.maintxt.unbind("click").unbind("blur").unbind("keyup").attr("disabled", "disabled");
    if (this.enable) {
        this.maintxt.mouseout(function () {
            var _this = $(this);
            setTimeout(function () {
                if (!_this.is(":focus")) {
                    _this.parent().parent().css("border", "1px solid #dedede");
                }
            }, 50);
        }).mouseover(function () {
            if (!$(this).is(":focus")) {
                $(this).parent().parent().css("border", "1px solid #15a4ff");
            }
        });
        this.maintxt.click(function (event) {
            $(this).parent().parent().css("border", "1px solid #15a4ff");
            if (_this.multiple) {
                _this.maintxt.val(_this.keywords);
            }
            _this.show();
        }).blur(function () {
            if (_this.maintxt.attr("in") != "1") {
                _this.keywords = "";
                //清除标记
                _this.maintable.find("i.sl").each(function () {
                    $(this).replaceWith($(this).html());
                });
                _this.maintable.find("tr:hidden").show();
                _this.maintxt.val(_this.selectedText).parent().parent().css("border", "1px solid #dedede");
                _this.droplistdiv.hide();
                //if (_this.niceScroll != null) _this.niceScroll.hide();
            }
        }).keyup(function () {
            var val = $(this).val();
            if (_this.keywords != val) {
                //清除标记
                _this.maintable.find("i.sl").each(function () {
                    $(this).replaceWith($(this).html());
                });
                _this.maintable.find("tr:hidden").show();
                _this.keywords = val; //刷新关键字
                if (val != "") {
                    //筛选包含关键字的项并标记。
                    var table = _this.maintable[0];
                    var ts = val.split(' ');
                    for (var i = 0; i < table.rows.length; i++) {
                        $(table.rows[i]).find("i").each(function () {
                            var xx = $(this).html();
                            $(this).replaceWith(xx);
                        });
                        var has = 0;
                        for (var k = 0; k < ts.length; k++) {
                            if (ts[k] == "" || ts[k] == " ") {
                                has++;
                                continue;
                            }
                            for (var j = 0; j < table.rows[i].cells.length; j++) {
                                if (table.rows[i].cells[j].className == "c") {
                                    continue;
                                }
                                var html = table.rows[i].cells[j].innerHTML;
                                if (html.indexOf(ts[k]) >= 0) {
                                    var re = new RegExp(ts[k], "g");
                                    html = html.replace(re, "<i class='sl'>" + ts[k] + "</i>");
                                    has++;
                                    table.rows[i].cells[j].innerHTML = html;
                                }
                            }
                        }
                        if (has != ts.length) {
                            table.rows[i].style.display = "none";
                        }
                    }
                }
                //if (_this.niceScroll != null) { _this.niceScroll.resize(); }
            }
        });
        this.maintxt.removeAttr("disabled");
        this.maindiv.css("background-color", "#fff");
        this.maintxt.css("background-color", "#fff");
        this.maindiv.find("a").css("background-color", "#fff");
    } else {
        this.maindiv.css("background-color", "#EBEBE4");
        this.maintxt.css("background-color", "#EBEBE4");
        this.maindiv.find("a").css("background-color", "#EBEBE4");
    }

    var val = this.selectedValue;
    this.droplistdiv.find("tr[class='selected']").removeClass("selected").find("td[class='c'] span").removeClass("checked");
    this.valuehidden.val("");
    this.maintxt.val("");
    if (val && val != "") {
        var vals = val.split(",");
        var filter = "";
        for (var i = 0; i < vals.length; i++) {
            filter += (filter == "" ? "" : ",") + "tr[value='" + vals[i] + "']";
        }
        this.selectedRows = this.droplistdiv.find(filter);
        if (this.selectedRows.length != 0) {
            if (!this.multiple) {
                this.selectedRow = $(this.selectedRows[0]);
                this.selectedRows = this.selectedRow;
            }
            this.selectedRows.addClass("selected").find("td[class='c'] span").addClass("checked");
            ;
            var value = "", text = "";
            this.selectedRows.each(function () {
                text += (text == "" ? "" : ",") + $(this).find("td[class='m']").text();
                value += (value == "" ? "" : ",") + $(this).attr("value");
            });
            this.valuehidden.val(value);
            this.maintxt.val(text);
            this.selectedValue = value;
            this.selectedText = this.maintxt.val();
        }
    }
}

//复选框
dys.checkBox.prototype.changed = function (checked) {
};
dys.checkBox.prototype.get = function () {
    return this.control;
};
dys.checkBox.prototype.ref = function () {
    if (this.checked) {
        this.control.removeClass("checkedhover").removeClass("hover").addClass("checked");
    } else {
        this.control.removeClass("checkedhover").removeClass("hover").removeClass("checked");
    }
    this.control.children("input").prop("checked", this.checked);
    this.control.children("label").html(this.text);

    this.control.unbind("mouseover").unbind("mouseout").unbind("click");
    if (this.enable) {
        var _this = this;
        var checkclick = function (event) {
            if (event.target.tagName == "INPUT") {
                return;
            }
            var input = $(this).children("input").eq(0);
            input.prop("checked", !input.prop("checked"));
            if (input.prop("checked")) {
                $(this).removeClass("checkedhover").removeClass("hover").addClass("checked");
            } else {
                $(this).removeClass("checkedhover").removeClass("hover").removeClass("checked");
            }
            _this.checked = input.prop("checked");
            if (_this.changed != null) {
                _this.changed(input.prop("checked"));
            }
            event.stopPropagation();
        };
        this.control.mouseover(dys.checkradiofunc.over).mouseout(dys.checkradiofunc.out).click(checkclick).each(dys.checkradiofunc.out).children("label").removeAttr("for");
    }
};

//单选框
dys.radioButton.prototype.changed = function (checked) {
};
dys.radioButton.prototype.get = function () {
    return this.control;
};
dys.radioButton.prototype.ref = function () {
    this.control.removeClass("checkedhover").removeClass("hover");
    if (this.checked) {
        this.control.addClass("checked");
        this.control.children("input").prop("checked", true);
    } else {
        this.control.removeClass("checked");
        this.control.children("input").prop("checked", false);
    }
    this.control.unbind("mouseover").unbind("mouseout").unbind("click");
    if (this.enable) {
        var _this = this;
        var radioclick = function (event) {
            if (event.target.tagName == "INPUT") {
                return;
            }
            var input = $(this).children("input").eq(0);
            if (input.prop("checked") == true) {
                return;
            }
            input.prop("checked", !input.prop("checked"));
            $(this).removeClass("checkedhover").removeClass("hover").addClass("checked");
            var rs = $(this).siblings(".radiobutton");
            rs.each(function () {
                var r = dys.get($(this).children("input").attr("id"));
                r.checked = false;
                r.ref();
            });
            _this.checked = input.prop("checked");
            if (_this.changed != null) {
                _this.changed(input.prop("checked"));
            }
            event.stopPropagation();
        }
        this.control.mouseover(dys.checkradiofunc.over).mouseout(dys.checkradiofunc.out).click(radioclick).each(dys.checkradiofunc.out).children("label").removeAttr("for");
    }

    this.control.children("label").html(this.text);
    if (this.checked == true) {
        var rs = this.control.siblings(".radiobutton");
        rs.each(function () {
            var r = dys.get($(this).children("input").attr("id"));
            r.checked = false;
            r.ref();
        });
    }
};

//文本框
dys.textBox.prototype.changed = function (text) {
}; //当值改变后失去焦点时触发
dys.textBox.prototype.changing = function (text) {
}; //当值在改变时触发
dys.textBox.prototype.get = function () {
    return this.control.parent().parent();
};
dys.textBox.prototype.ref = function () {
    this.control.unbind("mouseout").unbind("mouseover").unbind("keyup").unbind("blur").unbind("focus").attr("disabled", "disabled").siblings("a").unbind("click").unbind("mouseover").unbind("mouseout");
    this.control.val(this.text);
    if (this.enable) {
        var texttemp = "";
        var _txt = this;
        if (this.message != "" && this.text == "") {
            this.control.val(this.message);
            this.control.css("color", "#999").attr("msg", "1");
        }

        //$(".textbox input,.textbox textarea")
        //文本框(包括多行文本框)
        this.control.mouseout(function () {
            var _this = $(this);
            setTimeout(function () {
                if (!_this.is(":focus")) {
                    _this.parent().parent().css("border", "1px solid #dedede");
                }
            }, 50);
        }).mouseover(function () {
            if (!$(this).is(":focus")) {
                $(this).parent().parent().css("border", "1px solid #15a4ff");
            }
        }).removeAttr("disabled").keyup(function () {
            if (_txt.text != $(this).val()) {
                _txt.text = $(this).val();
                _txt.changing($(this).val());
            }
            _txt.validate();
        }).focus(function () {
            if ($(this).attr("msg") == "1") {
                $(this).val("").removeAttr("msg").css({ "color": "#404040" });
            }
            $(this).parent().parent().css("border", "1px solid #15a4ff");
            if ($.browser.msie && $.browser.version == 9.0) {
                return;
            }
            if ($(this).parent().parent().attr("class") == "textbox") {
                var r = $(this).is("input") ? 4 : 13;
                $(this).siblings("a").addClass("focus").css({
                    right: r
                });
            }
            texttemp = $(this).val();
        }).blur(function () {
            if (_txt.message != "" && _txt.text == "") {
                _txt.control.val(_txt.message);
                _txt.control.css("color", "#999").attr("msg", "1");
            }

            if ($(this).attr("in") != "1") {
                var _this = $(this);
                setTimeout(function () {
                    _this.parent().parent().css("border", "1px solid #dedede");
                    if ($.browser.msie && $.browser.version == 9.0) {
                        return;
                    }
                    if (_this.parent().parent().attr("class") == "textbox") {
                        _this.siblings("a").removeClass("focus");
                    }
                }, 50);
            }
            if (texttemp != $(this).val()) {
                _txt.changed($(this).val());
            }
            _txt.validate();
        }).siblings("a").click(function () {
            var cl = $(this).parent().parent().attr("class");
            if (cl == "textbox") {
                $(this).siblings("input,textarea").val("").focus();
            }
        }).mouseover(function () {
            $(this).siblings("input,textarea").attr("in", 1);
        }).mouseout(function () {
            $(this).siblings("input,textarea").removeAttr("in");
        });
        this.control.parent().css("background-color", "#fff");
        this.control.css("background-color", "#fff");
    } else {
        this.control.parent().css("background-color", "#EBEBE4");
        this.control.css("background-color", "#EBEBE4");
    }
};
dys.textBox.prototype.validate = function () {
    if (this.notNull == true && this.text == "") {
        dys.tooltip.show("不允许空值!", this.id);
        return false;
    }
    if (this.text.length > this.maxLength) {
        dys.tooltip.show("只允许输入长度小于 " + this.maxLength + " 的值!", this.id);
        return false;
    }
    if (this.text.length < this.minLength) {
        dys.tooltip.show("只允许输入长度大于 " + this.minLength + " 的值!", this.id);
        return false;
    }
    if (this.dataType == dys.dataType.number || this.dataType == dys.dataType.int || this.dataType == dys.dataType.double) {
        var error = "";
        switch (this.dataType) {
            case dys.dataType.number:
                error = "数值";
                break;
            case dys.dataType.int:
                error = "整数";
                break;
            case dys.dataType.double:
                error = "小数";
                break;
            default:
                error = "数值";
                break;
        }
        if (isNaN(this.text)) {
            dys.tooltip.show("只允许输入" + error + "!", this.id);
            return false;
        }
        var value = parseFloat(this.text);
        if (value > this.max) {
            dys.tooltip.show("只允许输入小于 " + this.max + " 的" + error + "!", this.id);
            return false;
        }
        if (value < this.min) {
            dys.tooltip.show("只允许输入大于 " + this.min + " 的" + error + "!", this.id);
            return false;
        }
    }
    return true;
}

//对话框
dys.dialogBox.prototype.close = function () {
    var _this = this;
    if (_this.full) {
        _this.full.parentNode.removeChild(_this.full);
        _this.fulliframe.parentNode.removeChild(_this.fulliframe);
    }
    var iframes = _this.obj.getElementsByTagName("iframe");
    for (var i = 0; i < iframes.length; i++) {
        iframes[i].parentNode.removeChild(iframes[i]);
    }
    if ($.browser.msie) {
        CollectGarbage();
    }
    if (_this.obj && _this.obj.parentNode) _this.obj.parentNode.removeChild(_this.obj);

    var temp = [];
    for (var d = 0; d < dys.dialog.array.length; d++) {
        if (dys.dialog.array[d].id != _this.id) {
            temp[temp.length] = dys.dialog.array[d];
        }
    }
    dys.dialog.array = temp;
    if (_this.pars.closed) {
        _this.pars.closed(_this.data);
    }
    _this.closed(_this.data);
};
dys.dialogBox.prototype.closed = function (data) {
};

//列表控件
dys.ajaxGrid.prototype.load = function () {
    var _this = this;
    _this.maindiv.children(".fullback,.loading").show();
    $.post("/dysoft/control.ashx?r=" + Math.random(), {
        t: "ajaxgrid",
        m: "getdata",
        index: this.pageIndex,
        size: this.pageSize,
        paging: this.allowPaging,
        where: this.where,
        orderby: this.orderby,
        base64str: this.base64str
    }, function (res) {
        eval(res);
        _this.maindiv.children(".fullback,.loading").hide();
        if (_this.pageIndex <= 0) {
            _this.bottomdiv.find(".pre").attr("disabled", "disabled");
        }
        else {
            _this.bottomdiv.find(".pre").removeAttr("disabled");
        }
        if (_this.pageIndex + 1 >= _this.pageCount) {
            _this.bottomdiv.find(".next").attr("disabled", "disabled");
        }
        else {
            _this.bottomdiv.find(".next").removeAttr("disabled");
        }
        _this.init();
        _this.resetsize();
    });
};

dys.ajaxGrid.prototype.getwhere = function (fielddiv) {
    var where = "";
    this.headdiv.children("div").each(function () {
        if (this == fielddiv) {
            return;
        }
        var w = "";
        var field = "nvl(" + $(this).attr("field") + ",'0123456789')";
        if ($(this).attr("values") != null && $(this).attr("values") != "") {
            w += field + " " + ($(this).attr("notin") == "not in" ? "not in" : "in") + " (" + $(this).attr("values") + ")";
        }
        var gjz = $(this).attr("gjz");
        if (gjz != null && gjz != "") {
            w += (w == "" ? "" : " or ") + field + " ";
            var ysf = $(this).attr("ysf");
            if (ysf == null) {
                ysf = "like";
            }
            if (ysf == "likeL") {
                w += "like '%" + gjz + "'";
            } else if (ysf == "likeR") {
                w += "like '" + gjz + "%'";
            } else if (ysf == "like" || ysf == "not like") {
                w += ysf + " '%" + gjz + "%'";
            } else {
                w += ysf + " '" + gjz + "'";
            }
        }
        if (w.indexOf(" or ") >= 0) {
            w = "(" + w + ")";
        }
        if (w == "") {
            return;
        }
        where += (where == "" ? "" : " and ") + w;
    });
    return where;
};

dys.ajaxGrid.prototype.refwhere = function () {
    this.where = this.getwhere();
    this.load();
    this.whereHidden.val(this.where);
};

dys.ajaxGrid.prototype.loadFilterItems = function (gjz, index, more) {
    var _this = this;
    var list = _this.filterdiv.children(".list");
    var values = _this.filterField.attr("values");
    var itemclick = function (item, indexx) {
        if (indexx) {
            item.html("加载中...");
            _this.loadFilterItems(_this.filterdiv.find(".search input").val(), indexx, item);
        } else {
            var tj = false;
            var notin = _this.filterField.attr("notin");
            if (item.hasClass("checked")) {
                item.removeClass("checked");
                tj = false;
            } else {
                item.addClass("checked");
                tj = true;
            }
            if (notin == "not in") {
                tj = !tj;
            }
            if (tj) {
                var v = _this.filterField.attr("values") == null ? "" : _this.filterField.attr("values");
                _this.filterField.attr("values", v + (v == "" ? "" : ",") + "'" + item.html() + "'");
            } else {
                var v = _this.filterField.attr("values");
                v = ("," + v + ",").replace(",'" + item.html() + "'", "");
                _this.filterField.attr("values", v.trim(","));
            }
        }
    };
    var addcheckitem = function () {
        if (values == null) {
            return;
        }
        var vs = values.split(",");
        var notin = _this.filterField.attr("notin");
        for (var i = 0; i < vs.length; i++) {
            if (vs[i] == "") {
                continue;
            }
            var checked = " checked";
            if (notin == "not in") {
                checked = checked == "" ? " checked" : "";
            }
            $("<a href='javascript:;' onfocus='this.blur();' class='checkbox" + checked + "'>" + vs[i].trim("'") + "</a>").click(function () {
                itemclick($(this));
            }).appendTo(list);
        }
    };
    var additem = function (text, indexx) {
        if (("," + values + ",").indexOf(",'" + text + "',") >= 0) {
            return;
        }
        var checked = "";
        var notin = _this.filterField.attr("notin");
        if (notin == "not in") {
            checked = checked == "" ? " checked" : "";
        }
        $("<a href='javascript:;' onfocus='this.blur();' class='checkbox" + (indexx ? " more" : "") + checked + "'>" + text + "</a>").click(function () {
            itemclick($(this), indexx);
        }).appendTo(list);
    };

    $.post("/dysoft/control.ashx?r=" + Math.random(), {
        t: "ajaxgrid",
        m: "getitems",
        field: _this.filterField.attr("field"),
        gjz: gjz,
        values: values,
        index: index ? index : 0,
        where: this.getwhere(_this.filterField[0]),
        base64str: this.base64str
    }, function (res) {
        list.removeClass("load");
        if (index == null) {
            addcheckitem();
        }
        eval(res);
        if (more) {
            more.remove();
        }
    });
};
dys.ajaxGrid.prototype.resetsize = function () {
    var fullwidth = this.dataheaderdiv.width() - this.headwidth - 2;
    var itemdiv;
    if (fullwidth > 0) {
        this.headdiv.removeAttr("style").children(".full").width(fullwidth).show();
        itemdiv = this.datadiv.children(".dataitem").children(".item").removeAttr("style");
        itemdiv.children(".full").width(fullwidth - (this.maindiv[0].scrollHeight > 0 ? 17 : 0)).show();
    } else {
        this.headdiv.css({ width: this.headwidth }).children(".full").width(0).hide();
        itemdiv = this.datadiv.children(".dataitem").children(".item").css({ width: this.headwidth });
        itemdiv.children(".full").width(0).hide();
    }

    if (this.offsetHeight != 0) {
        this.height($(window).height() + this.offsetHeight);
    }
    this.datadiv.scrollTop(0).children(".databtns").css({
        right: (this.datadiv[0].scrollHeight > this.datadiv.height() ? 17 : 0)
    }).scrollTop(0);
};
dys.ajaxGrid.prototype.init = function () {
    var _this = this;
    var itemdiv = this.datadiv.children(".dataitem").children(".item");
    itemdiv.mouseover(function () {
        $(this).css({ backgroundColor: "#EFF1F8" });
        _this.datadiv.children(".databtns").children().eq($(this).index()).css("background-color", "#EFF1F8");
    }).mouseout(function () {
        $(this).css({ backgroundColor: "" });
        _this.datadiv.children(".databtns").children().eq($(this).index()).css("background-color", "");
    });
    _this.datadiv.children(".databtns").children().mouseover(function () {
        $(this).css({ backgroundColor: "#EFF1F8" });
        itemdiv.eq($(this).index()).css("background-color", "#EFF1F8");
    }).mouseout(function () {
        $(this).css({ backgroundColor: "" });
        itemdiv.eq($(this).index()).css("background-color", "");
    })
};

dys.ajaxGrid.prototype.height = function (height) {
    this.maindiv.height(height);
    this.fullback.css({ height: height })
    this.datadiv.height(height - 34 - 35 - 34);
    this.datadiv.children(".databtns").height(height - 34 - 35 - 34 - (this.datadiv[0].scrollWidth > this.datadiv.width() ? 17 : 0));
};

$(function () {
    $(document).mousedown(function () {
        top.$(".dy_calendar.picker").remove();
    });
    $(window).scroll(function () {
        $(".droplistdiv").hide();
        //$(window).click();
    });
    $(window).resize(function () {
        var cals = top.$(".dy_calendar.picker");
        if (cals.length > 0) {
            cals.css({ display: "none" });
            var div = $("#" + cals.attr("maintxt")).parent();
            setTimeout(function () {
                var x = div.offset().left;
                var y = div.offset().top + div.height() + 1;
                if (x + cals.width() > $(document).width()) {
                    x = x - (cals.width() - div.width());
                }

                var calheight = Number(cals.attr("height"));
                if (y + calheight > $(document).height()) {
                    y = y - div.height() - calheight - 2;
                    if ($.browser.msie && $.browser.version == 6.0) {
                        y++;
                    }
                } else {
                    if ($.browser.msie && $.browser.version == 6.0) {
                        y--;
                    }
                }
                cals.css({
                    display: "",
                    left: x,
                    top: y
                });
            }, 10);
        }
    });
});
